<% @page_title = "多背一公斤 | 我收到的消息" %>

<% content_for :sidebar do -%>
  <h4><%= link_to "看我发出的消息", outbox_messages_url %></h4>
<% end -%>

<h3>我收到的消息</h3>
<% form_for :messages, :url => destroy_all_messages_url, :html => {:method => 'delete'} do |f| -%>
<table border="0" cellspacing="0" cellpadding="3" class="left ol" width="98%">
  <tr>
    <th>来自</th>
    <th>主题</th>
    <th>时间</th>
    <th>选择</th>
  </tr>
<% @messages.each_with_index do |msg, index| -%>
  <tr>
    <td><%= msg.sender_name %></td>
    <td><%= message_link msg %></td>
    <td><%= msg.created_at.to_date %></td>
    <td><input name="messages[no_<%= index %>]" type="checkbox" value="<%= msg.id %>" />
        <input name="messages[no_<%= index %>]" type="hidden" value="0" /></td>
  </tr>
<% end -%>
</table>
<p style="text-align:right">
  <a href="javascript:void(0)" onclick="CheckAll(true)">全选</a> 
  <a href="javascript:void(0)" onclick="CheckAll(false)">全取消</a> 
  <%= submit_tag "删除选中的消息" %>
</p>
<% end -%>
<%= will_paginate %>

<script type="text/javascript">/*<![CDATA[*/
    function CheckAll(value) 
    {
        var boxes=document.getElementsByTagName("input");
        for(var i=0; i<boxes.length; i++) {
            if (boxes[i].type=='checkbox') {
                boxes[i].checked=value;
            }
        }
    }
/*]]>*/</script>